package net.borlis.sample.service.repositories.common;

import net.borlis.dictionaries.product.SaleType;
import net.borlis.sample.service.entities.common.Constants;
import net.borlis.sample.service.entities.configuration.interfaces.IVitoAddressEntity;
import net.borlis.sample.service.entities.configuration.interfaces.IVitoEntity;
import net.borlis.sample.service.entities.configuration.interfaces.IVitoProviderConfigurationEntity;
import net.borlis.sample.service.entities.configuration.parents.VitoEntity;
import net.borlis.sample.service.entities.configuration.parents.VitoProviderEntity;
import net.borlis.sample.service.entities.configuration.working.*;
import net.borlis.sample.service.entities.customer.DynamixAccountEntity;
import net.borlis.sample.service.entities.customer.DynamixCustomerEntity;
import net.borlis.sample.service.entities.general.*;

import java.util.Date;

/**
 * @author alex@borlis.net on 02.06.2014.
 */
public final class RepoEntityCreator {

    private static final Long SERGEY_ACCOUNT_TT_AUTH_ID = new Long(999999);

    private RepoEntityCreator() {
    }

    public static DynamixLocaleEntity createLocale() {
        return new DynamixLocaleEntity("de-DE", "Deutsch");
    }

    public static CountryEntity createCountry() {
        return new CountryEntity("Germany", createCurrency());
    }

    public static CurrencyEntity createCurrency() {
        return new CurrencyEntity("EUR");
    }

    public static CurrencyDetailEntity createCurrencyDetail(CurrencyEntity currency) {
        return new CurrencyDetailEntity("Euro", "UE money", currency, createLocale());
    }

    public static IVitoEntity createVito(CountryEntity country, DynamixAccountEntity account) {
        return new VitoWorking("MVRK", "Maverick & Co", country,
                new AttachedMainOrganisationWorking(Constants.FAKE_CDS_MAIN_ORGANISATION_ID, "777", account), account);
    }

    public static IVitoEntity createVito(DynamixAccountEntity account) {
        return createVito(createCountry(), account);
    }

    public static DynamixAccountEntity createDynamixAccount() {
        return new DynamixAccountEntity("Sergey", "Mavrov", "maverick", SERGEY_ACCOUNT_TT_AUTH_ID,
                new DynamixCustomerEntity("MAV", "The test dynamix customer for the maverick account."));
    }

    public static DynamixCustomerEntity createDynamixCustomer() {
        return new DynamixCustomerEntity("DCE", "The dynamix customer for test.");
    }

    public static IVitoAddressEntity createVitoAddress(IVitoEntity vito, CountryEntity country,
                                                       DynamixAccountEntity account) {
        return new VitoAddressWorking((VitoWorking) vito, country, "Mr.", "Dear", "Sergey",
                "Mavrov", "Julicher Strasse", "US007", "Aachen", "+49-007-007-007", "+49-008-008-008",
                "+49-009-009-009", "james.bond@cia.us", account);
    }

    public static TravelPeriodWorking createTravelPeriod(VitoEntity vito, DynamixAccountEntity account, String travelPeriodName, Date startDate) {
        return new TravelPeriodWorking(travelPeriodName, startDate, (VitoWorking) vito, account);
    }

    public static TravelDurationEntity createTravelDuration() {
        final int durationFrom = 5;
        final int durationTo = 7;
        return new TravelDurationEntity(durationFrom, durationTo);
    }

    public static VitoProviderEntity createVitoProvider(VitoEntity vito, DynamixAccountEntity account,
                                                        DynamixProviderTypeEntity type) {
        CurrencyEntity currencyProvider = new CurrencyEntity("LAT");
        CountryEntity country = new CountryEntity("LTV", currencyProvider);
        ProviderEntity provider = new ProviderEntity("LATVIA");
        DynamixProviderEntity dynProvider = new DynamixProviderEntity(Constants.FAKE_PROVIDER_CDS, "LDP", provider, country);
        // -=-=-=-
        DynamixProviderSubtypeEntity subType = new DynamixProviderSubtypeEntity("Charter", "Private flight option");
        CombinedDynamixProviderTypeEntity combType = new CombinedDynamixProviderTypeEntity("Flight-Charter", "", type, subType);
        // -=-=-=-
        TypedDynamixProviderEntity typedDynamixProvider = new TypedDynamixProviderEntity(dynProvider, combType);
        // -=-=-=-
//        CurrencyEntity currencyVito = new CurrencyEntity("ROL");
//        CurrencyDetailEntity currencyDetail1 = new CurrencyDetailEntity("Leul românesc", "Bani romanian",
//                currencyVito, new DynamixLocaleEntity("ro_RA", "Român in Romania"));
//        CurrencyDetailEntity currencyDetail2 = new CurrencyDetailEntity("Romanian leu", "Romanian money",
//                currencyVito, new DynamixLocaleEntity("en_EN", "English in England"));
        // -=-=-=-
        VitoConfigurationWorking vitoConf = new VitoConfigurationWorking(true, SaleType.Total, (VitoWorking) vito,
                typedDynamixProvider, account);
        return new VitoProviderWorking(true, vitoConf, account);
    }

    public static IVitoProviderConfigurationEntity createVitoProviderConfiguration(IVitoEntity vito,
                                                                                   DynamixAccountEntity account,
                                                                                   DynamixProviderTypeEntity type) {
        final int relDays = 5;
        return new VitoProviderConfigurationWorking(true, relDays, createTravelPeriod((VitoEntity) vito, account, "createVitoProviderConfiguration_TP", new Date()),
                (VitoProviderWorking) createVitoProvider((VitoEntity) vito, account, type), account);
    }

    public static PaymentSystemEntity createPaymentSystem() {
        return new PaymentSystemEntity(Constants.FAKE_CDS_PAYMENT_SYSTEM_ID, "VISA");
    }

    public static CombinedDynamixProviderTypeEntity createCombinedDynamixProviderType(String providerTypeLabel,
                                                                                      String providerTypeDescription,
                                                                                      String dynamixproviderSubtypeLabel,
                                                                                      String dynamixproviderSubtypeDescription,
                                                                                      String combTypeLabel,
                                                                                      String combTypeDescriptionl,
                                                                                      DynamixProviderTypeEntity type) {
        DynamixProviderSubtypeEntity dpst = new DynamixProviderSubtypeEntity(dynamixproviderSubtypeLabel, dynamixproviderSubtypeDescription);
        CombinedDynamixProviderTypeEntity cdpt = new CombinedDynamixProviderTypeEntity();
        cdpt.setDescription(combTypeDescriptionl);
        cdpt.setLabel(combTypeLabel);
        cdpt.setProviderSubType(dpst);
        cdpt.setProviderType(type);
        return cdpt;
    }
}
